package tq.com.tqstudent.net.ok;

import android.app.Activity;

import com.lib.common.base.BaseActivity;
import com.lzy.okgo.OkGo;

import tq.com.tqstudent.Constants;
import tq.com.tqstudent.bean.BaseBean;
import tq.com.tqstudent.protocol.NetCallback;

/**
 * @Author rames
 * @date 2019/3/8 15:18
 */
public class OkGoUtils<T> {

    public static <T> void post(BaseActivity activity, String url, String paramJson, NetCallback<T> callback){
        OkGo.<BaseBean<T>>post(Constants.HTTP_URL + url)
                .tag(activity)
                .upJson(paramJson)
                .execute(new DialogCallback<T>(activity) {
                    @Override
                    public void handleSuccess(T data) {
                        if(null != callback) {
                            callback.onSuccess(data);
                        }
                    }

                    @Override
                    public void handleFail(BaseBean body) {
                        if(null == body) {
                            activity.showToast("请求失败");
                            return;
                        }

                        switch (body.getRet()) {
                            case 10000:
                                activity.showToast("系统错误");
                                break;

                            case 10010:
                                activity.showToast("无效请求");
                                break;

                            case 10011:
                                activity.showToast("身份过期或者无效");
                                break;

                            default:
                                activity.showToast("请求失败");
                                break;
                        }
                    }
                });
    }

    public static void postString(Activity activity, String url, String paramJson){
//        OkGo.<String>post(Constants.HTTP_URL+url)
//                .tag(activity)
//                .upJson(paramJson)
//                .execute(new DialogCallback<String>(activity) {
//                    @Override
//                    public void onSuccess(Response<String> response) {
//
//                        LogUtil.e("response:"+response.body());
//                    }
//                });
    }
}
